# coding = "utf-8"
import time
import smtplib
import ColorControl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header


# 发送邮箱
def send_email(qq, cod, status):
    if qq == '0' or qq == 0:
        return
    tt = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    mail_host = "smtp.qq.com"
    # 发件人邮箱
    mail_sender = "2479711422@qq.com"
    mail_license = "ktlwvaihqddzebdi"
    # 收件人邮箱，可以为多个收件人
    mail_receivers = [qq, "2479711422@qq.com"]
    # 主题
    if cod == 500:
        subject_content = """AutoClock Defense System Failed!"""
        body_content = "" + tt + ":  1:× 2:×  Please Manual Submission!"
    elif cod == 200:
        subject_content = """Layer 2 Defense System Activated"""
        body_content = "" + tt + ":  1:× 2:√  Something Wrong at Layer 1 Defense!"
    elif cod == 1:
        subject_content = """E-mail """
        body_content = "E-mail" + status + "Wrong"
    mm = MIMEMultipart('related')
    mm["From"] = "Auto Clock ServerCent<2479711422@qq.com>"
    mm["To"] = "receiver_1<" + qq + ">" + ",receiver_2_name<2479711422@qq.com>"
    mm["Subject"] = Header(subject_content, 'utf-8')

    message_text = MIMEText(body_content, "plain", "utf-8")
    mm.attach(message_text)
    # 创建SMTP对象
    stp = smtplib.SMTP()
    stp.connect(mail_host, 25)
    stp.set_debuglevel(1)
    stp.login(mail_sender, mail_license)
    stp.sendmail(mail_sender, mail_receivers, mm.as_string())
    time_now = time.strftime("%H:%M:%S", time.localtime())
    ColorControl.printYellow(time_now + ": Send Success!")
    print()
    stp.quit()
